import 'package:badges/badges.dart';
import 'package:erp/main_state.dart';
import 'package:erp/res/colors.dart';
import 'package:erp/routes/app_pages.dart';
import 'package:erp/util/image_utils.dart';
import 'package:erp/widgets/load_image.dart';
import 'package:erp/widgets/my_app_bar.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import 'controller.dart';
import 'widgets/menu_icon.dart';

class IndexPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    MainState ms = Get.find<MainState>();
    var controller = Get.put(IndexController());
    return Container(
      decoration: BoxDecoration(
        color: Colours.bg_color,
        image: DecorationImage(
          alignment: Alignment.topCenter,
          image: ImageUtils.getImageProvider("", holderImg: 'index/banner'),
          fit: BoxFit.fitWidth,
        ),
      ),
      child: Scaffold(
        backgroundColor: Colors.transparent,
        appBar: MyAppBar(
          isBack: false,
          backgroundColor: Colors.transparent,
          centerTitle: '首页',
        ),
        body: Stack(
          children: [
            Positioned(
              top: 90.h,
              left: 52.w,
              child: Text(
                "你好，${ms.userInfo.value!.empName}",
                style: TextStyle(
                  color: Colors.white,
                  fontSize: 32.sp,
                  fontWeight: FontWeight.w400,
                ),
              ),
            ),
            Positioned(
              left: 32.w,
              right: 32.w,
              top: 150.h,
              child: Container(
                width: 686.w,
                height: 240.h,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.all(Radius.circular(20.r)),
                  color: Colors.white,
                  boxShadow: [
                    BoxShadow(
                      offset: Offset(0, 4.w),
                      blurRadius: 8.r,
                      spreadRadius: 0,
                      color: Color.fromRGBO(76, 136, 255, 0.2),
                    )
                  ],
                ),
                child: Row(
                  children: [
                    Padding(
                      padding: EdgeInsets.only(
                        top: 50.h,
                        left: 60.w,
                      ),
                      child: Obx(
                        () => Badge(
                          showBadge: controller.count.value > 0,
                          badgeColor: Color(0xffFC4D2E),
                          badgeContent: Text(
                            "${controller.count}",
                            style: TextStyle(
                              color: Colors.white,
                            ),
                          ),
                          child: MenuIcon(
                            title: "流程中心",
                            icon: LoadAssetImage(
                              "index/flow_center",
                              width: 94.w,
                              height: 94.w,
                            ),
                            onTap: () {
                              controller.jumpToProcess();
                            },
                          ),
                        ),
                      ),
                    ),
                    Offstage(
                      child: Padding(
                        padding: EdgeInsets.only(
                          top: 50.h,
                          left: 60.w,
                        ),
                        child: MenuIcon(
                          title: "立项管理",
                          icon: LoadAssetImage(
                            "index/sale_project",
                            width: 94.w,
                            height: 94.w,
                          ),
                          onTap: () {
                            Get.toNamed(Routes.PROJECT_MANAGEMENT);
                          },
                        ),
                      ),
                      offstage: !ms.menuCodeList.contains("Pm"),
                    )
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
